using System;
using log4net.Config;
using Microsoft.Practices.ServiceLocation;
using NHibernate;
using NUnit.Framework;
using SIP.PN.Infraestructura.Initializer;

namespace SIP.PN.TestDeIntegracion
{
    public class TestBase
    {
		[SetUp]
		public virtual void SetUp()
		{
        }

        [TestFixtureSetUp]
        public void TestFixtureSetUp()
        {
            Initializer.StartUp();

            XmlConfigurator.Configure();
        }

        [TearDown]
        public void TearDown()
        {
            AssertsSessionFactory(ServiceLocator.Current.GetInstance<ISessionFactory>("ISessionFactoryWEB"));
        }

        private void AssertsSessionFactory(ISessionFactory sessionFactory)
        {
            Assert.IsNotNull(sessionFactory);

            Console.WriteLine("SessionOpenCount " + sessionFactory.Statistics.SessionOpenCount);
            Console.WriteLine("SessionCloseCount " + sessionFactory.Statistics.SessionCloseCount);
            Console.WriteLine("TransactionCount " + sessionFactory.Statistics.TransactionCount);
            Console.WriteLine("ConnectCount " + sessionFactory.Statistics.ConnectCount);
            Console.WriteLine("QueryExecutionCount " + sessionFactory.Statistics.QueryExecutionCount);

            Assert.AreEqual(sessionFactory.Statistics.SessionOpenCount, sessionFactory.Statistics.SessionCloseCount);
            sessionFactory.Statistics.Clear();
        }

        [TestFixtureTearDown]
        public void TestFixtureTearDown()
        {
            Initializer.ShutDown();
        }
    }
}